//
//  DCDriverEmptyViewController.m
//  JiuyaoMotorcade
//
//  Created by 大橙子 on 2018/12/1.
//  Copyright © 2018 Tomous. All rights reserved.
//

#import "DCDriverEmptyViewController.h"
#import "DCDriverEmptyCell.h"
#import "DCEvaluateViewController.h"
@interface DCDriverEmptyViewController ()<UITableViewDelegate,UITableViewDataSource,driverEmptyCellDelegate>

@property (nonatomic,strong) UITableView *tableView;
@property (nonatomic,strong) NSMutableArray *dataSource;

@end

@implementation DCDriverEmptyViewController
-(UITableView *)tableView
{
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.width, ScreenHeight - navHeight - statusHeight-50) style:UITableViewStylePlain];
        _tableView.separatorStyle = UITableViewCellStyleDefault;
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.backgroundColor = BackgroundColor;
        _tableView.rowHeight = 210;
    }
    return _tableView;
}
-(NSMutableArray *)dataSource
{
    if (!_dataSource) {
        _dataSource = [NSMutableArray new];
    }
    return _dataSource;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    NSArray *array = @[
                       @{
                           @"plateNum":@"京A11111",
                           @"name":@"张三",
                           @"state":@"满载",
                           @"tel":@"17600907892",
                           @"location":@"北京市顺义区临河南大街9号院",
                           @"pingjia":@"85%好评",
                           },
                       @{
                           @"plateNum":@"京A22222",
                           @"name":@"李四",
                           @"state":@"满载",
                           @"tel":@"17600907892",
                           @"location":@"北京市顺义区临河南大街9号院",
                           @"pingjia":@"85%好评",
                           },
                       @{
                           @"plateNum":@"京A33333",
                           @"name":@"张三",
                           @"state":@"满载",
                           @"tel":@"17600907892",
                           @"location":@"北京市顺义区临河南大街9号院",
                           @"pingjia":@"85%好评",
                           },
                       @{
                           @"plateNum":@"京A44444",
                           @"name":@"张三",
                           @"state":@"满载",
                           @"tel":@"17600907892",
                           @"location":@"北京市顺义区临河南大街9号院",
                           @"pingjia":@"85%好评",
                           },
                       ];
    [self.dataSource removeAllObjects];
    self.dataSource = [DCDriverManagerModel mj_objectArrayWithKeyValuesArray:array];
    [self.view addSubview:self.tableView];
}

#pragma tableViewDelegate
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataSource.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    DCDriverEmptyCell *cell = [DCDriverEmptyCell cellWithTableView:tableView];
    cell.model = self.dataSource[indexPath.row];
    cell.delegate = self;
    return cell;
}
//-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
//{
//    return kBaseSubViewHeight*2+130;
//}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    //    DCCarDetailMsgViewController *detailVC = [[DCCarDetailMsgViewController alloc]init];
    //    [[UIViewController currentViewController].navigationController pushViewController:detailVC animated:YES];
}
#pragma driverEmptyCellDelegate
-(void)selectedWithZhuxiao:(NSString *)content {
     DCLog(@"注销");
    __weak typeof(self) weakself = self;
    [self alertViewWithTitle:@"是否注销司机张三" sure:^(BOOL isSuccess) {
        [weakself showMessage:@"注销张三成功" afterDelay:1.0];
    } cancle:^(bool isFaile) {
        
    }];
}
-(void)selectedWithChakanPingjia:(NSString *)content {
    DCLog(@"查看评价");
    DCEvaluateViewController *evaluaeVC = [[DCEvaluateViewController alloc]initWithDriver:content];
    [[UIViewController currentViewController].navigationController pushViewController:evaluaeVC animated:YES];
}
-(void)selectedWithJionBlack:(NSString *)content {
   DCLog(@"加入黑名单");
    __weak typeof(self) weakself = self;
    [self alertViewWithTitle:@"是否将张三加入黑名单" sure:^(BOOL isSuccess) {
        [weakself showMessage:@"张三已加入黑名单" afterDelay:1.0];
    } cancle:^(bool isFaile) {
        
    }];
}
-(void)alertViewWithTitle:(NSString *)title sure:(void(^)(BOOL isSuccess))sure cancle:(void(^)(bool isFaile))cancle {
    
    UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"提示" message:title preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
        if (sure) {
            sure(YES);
        }
    }];
    UIAlertAction *cancleAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
    [alertVC addAction:sureAction];
    [alertVC addAction:cancleAction];
    [self presentViewController:alertVC animated:YES completion:nil];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
